package org.bridgen.runtime.model;

import org.bridgen.runtime.util.Interval;

/**
 * Bridgit is covered by the new BSD License. 
 * You should have received a copy of the new BSD license with Bridgit.
 * 
 * @author Emma Söderberg <emma add cs.lth.se>
 * Copyright (c) 2009
 */

public abstract class Island extends LexicalNode {

	protected Bridge bridge;
	protected boolean fake;
	protected boolean recoveredWithMatch;

	public Island(LexicalNode previous, Interval interval, String value) {
		super(previous, interval, value);
		fake = false;
		recoveredWithMatch = true;
	}


	public void setBridge(Bridge bridge) {
		this.bridge = bridge;
	}
	public boolean hasBridge() {
		return bridge != null;
	}
	public Bridge getBridge() {
		return bridge;
	}
	public void setFake(boolean isFake, boolean foundMatch) {
		fake = isFake;
		recoveredWithMatch = foundMatch;
	}
	public boolean isFake() {
		return fake;
	}
	public boolean recoveredWithMatch() {
		return recoveredWithMatch;
	}

	public String toString() {
		return super.toString()  + (isFake()?" (fake)":"");
	}

	public abstract boolean bridgeMatch(Island target, int tol);
	public abstract Bridge buildBridge(Island target, int tol);

	public abstract boolean possibleConstructionSite(LexicalNode node);
	public abstract Island constructFakeIsland(LexicalNode node, boolean intervalEnd);
	/*
	public abstract void insertFakeIsland(Island island, LexicalNode node);
	*/

	public abstract boolean startOfBridge();
}
